<?php 
header('content-type:application/json; charset=utf-8');
defined('IN_PHPCMS') or exit('No permission resources.');
//模型缓存路径
define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);

pc_base::load_app_func('util','content');
class api{
    
    public function __construct() {
		$this->db = pc_base::load_model('content_model');
		$this->position = pc_base::load_model('position_data_model');
	}

	public function category(){

		$res = subcat(0,0,0,1);
		$res = $this->category_format($res);
		foreach($res as $key=>$val){

			$val['child'] = $this->category_format(subcat($val['catid'],0,0,1));
			$data[]=$val;
		}
		echo json_encode(array('status'=>1,'info'=>'success','list'=>$data));
	}
    
    public function lists(){

    	$content = pc_base::load_app_class('content_tag');
    	$catid =$_GET['catid'];
    	$limit = $_GET['limit'];
    	if($catid>0){
    		$data['catid'] = $catid;
    	}elseif($catid=='all'){

    		$data['all'] = 'all';
    		$data['where'] = "status=99 and thumb!=''";
    		$data['order'] = "id desc";
    	}else{

    		echo json_encode(array('status'=>0,'info'=>'catid错误'));exit;
    	}

    	if($limit){

    		$data['limit'] = $limit;
    	}
    	$res = $content->lists($data);
    	if($res){

    		echo json_encode(array('status'=>1,'info'=>'success','list'=>$res));
    	}else{
    		echo json_encode(array('status'=>2,'info'=>'none'));
    	}
        
    }
	private function category_format($res){

		foreach($res as $key=>$val){

			//unset($val['siteid']);
			$data[] = array(
                    
                    'catid' =>$val['catid'],
                    'catname' => $val['catname'],
				);
		}
		return $data;
	}
}
 ?>
